//
//  GRRefusedVC.m
//  test
//
//  Created by 李彦宏 on 2018/3/12.
//  Copyright © 2018年 朱圳. All rights reserved.
//被拒绝

#import "GRRefusedVC.h"
#import "GRRefusedCell.h"//被拒绝cell
#import "GRRefusedHead.h"//被拒绝head
#import "JWGRRefuseLookVC.h"
#import "Utility.h"
#import "JWGRUsermodel.h"
#import "JWUserManager.h"
#import "JWGROtherFeemodel.h"

@interface GRRefusedVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) JWGRUsermodel *Gmodel;
@property (nonatomic, strong) JWGROtherFeemodel *model;
@property (nonatomic, strong) NSMutableArray *contArry;//内容
@end

@implementation GRRefusedVC
//UItableView初始化
- (void)setupTable
{
    UITableView *tableView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    //隐藏组距导航栏的间距
    tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    tableView.backgroundColor=[UIColor whiteColor];
    tableView.showsHorizontalScrollIndicator=NO;
    tableView.showsVerticalScrollIndicator=NO;
    tableView.dataSource=self;
    tableView.delegate=self;
    tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:tableView];
    self.tableView=tableView;
    

}
/*push出来的视图，先viewDidLoad 后viewWillAppear:(BOOL)animated
pop回来的视图，先viewWillAppear，后viewDidLoad；
 */
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [EasyShowOptions sharedEasyShowOptions].lodingShowType =  LodingShowTypeTurnAround ;
    [EasyShowOptions sharedEasyShowOptions].textStatusType =  ShowTextStatusTypeStatusBar ;
    [EasyShowLodingView showLodingText:@""];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self setdata];
        [EasyShowLodingView hidenLoding];
    });
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTable];
    self.Gmodel=[JWUserManager Gme];
    self.view.backgroundColor=[UIColor whiteColor];
    self.title=@"被拒绝";

}

#pragma -mark -----------------------------tableview datasource and delegate---------------------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.contArry.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    GRRefusedCell *cell=[GRRefusedCell cellwithTableview:tableView];
    self.model=self.contArry[indexPath.row];
    NSString *time =[Utility getDateStringWithTimeStr:self.model.time];
    
    cell.data.text=time;
    
    #pragma -mark ———————————跳转界面传第数据—————————————————
    cell.BUttonBlock = ^{
        
        JWGRRefuseLookVC *vc=[[JWGRRefuseLookVC alloc]init];
        vc.title=@"拒绝内容详情";
        self.model=self.contArry[indexPath.row];
//传递数据，下一页面的数组来存储，在这里初始化，下个页面不用懒加载
        vc.arry=[[NSMutableArray alloc]init];
        [vc.arry addObject:self.model];
        
        [self.navigationController pushViewController:vc animated:YES];
    };
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

#pragma -mark 头部的内容
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    GRRefusedHead *head=[[GRRefusedHead alloc]init];
    
    return head;
}


#pragma -mark ———————————————被拒绝数据————————————————————
-(void)setdata{
    if(self.Gmodel.ID==nil){
        self.Gmodel.ID=self.Gmodel.gid;
    }
    NSDictionary *dic=@{
                        @"jwid" : JWid,
                        @"jwpassword" : JWpassword,
                        @"gid":self.Gmodel.ID,
                        @"state":@"2",
                        };
    NSLog(@"--dic--%@", dic);
    [[AFNetworkTool shareManager]postJSONWithUrl:JWteacher_GROthFeelist parmas:dic successData:^(id json) {
        [self.contArry removeAllObjects];
        NSArray *arry=json[@"list"];
        for(int i=0;i<arry.count;i++){
            self.model=[JWGROtherFeemodel yy_modelWithJSON:arry[i]];
            [self.contArry addObject:self.model];
        }
        __weak typeof(self) weakslf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            if(self.contArry.count==0){
                [self.tableView removeFromSuperview];
                
                KongDataView *konview=[KongDataView NilDataview];
                konview.frame=self.view.frame;
                [self.view addSubview:konview];
            }
            [weakslf.tableView reloadData];
        });
        
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
    }];
    
}
//避免错误，创建数组就懒加载吧
-(NSMutableArray *)contArry{
    if(_contArry==nil){
        _contArry=[[NSMutableArray alloc]init];
    }
    return _contArry;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
